added Feb 2001 SDK
[windows-sources.git] / shared source / sscli20 / jscript / engine / cmdlineexception.cs
blob29bc2eafb005f76d7ac9e57103012ab7a0e36e98
1 // ==++==
2 //
3 //
4 // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
5 //
6 // The use and distribution terms for this software are contained in the file
7 // named license.txt, which can be found in the root of this distribution.
8 // By using this software in any fashion, you are agreeing to be bound by the
9 // terms of this license.
10 //
11 // You must not remove this notice, or any other, from this software.
12 //
13 //
14 // ==--==
16 namespace Microsoft.JScript{
18 using System;
19 using System.Globalization;
20 using Microsoft.JScript;
21 using System.Runtime.Serialization;
22 using System.Security.Permissions;
24 [Serializable]
25 public class CmdLineException: Exception{
26 private CmdLineError errorCode;
27 private string context;
28 private CultureInfo culture;
29 const int LOCALE_USER_DEFAULT = 0x0400;
31 public CmdLineException(CmdLineError errorCode, CultureInfo culture){
32 this.culture = culture;
33 this.errorCode = errorCode;
36 public CmdLineException(CmdLineError errorCode, string context, CultureInfo culture){
37 this.culture = culture;
38 this.errorCode = errorCode;
39 if (context != "")
40 this.context = context;
43 public CmdLineException() : base() {
46 public CmdLineException(string m) : base(m) {
49 public CmdLineException(string m, Exception e) : base(m, e) {
52 protected CmdLineException(SerializationInfo s, StreamingContext c) : base(s, c) {
53 this.errorCode = (CmdLineError)s.GetInt32("ErrorCode");
54 this.context = s.GetString("Context");
55 int lcid = s.GetInt32("LCID");
56 if (lcid != LOCALE_USER_DEFAULT)
57 this.culture = new CultureInfo(lcid);
60 [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter=true)]
61 public override void GetObjectData(SerializationInfo s, StreamingContext c)
63 base.GetObjectData(s, c);
64 s.AddValue("ErrorCode", (int)this.errorCode);
65 s.AddValue("Context", this.context);
66 int lcid = LOCALE_USER_DEFAULT;
67 if (this.culture != null)
68 lcid = this.culture.LCID;
69 s.AddValue("LCID", lcid);
72 public override string Message{
73 get{
74 string key = this.ResourceKey(this.errorCode);
75 string msg;
76 msg = JScriptException.Localize(key, this.context, this.culture);
77 // convert errorCode to a 4-digit string
78 string errorNum = (10000 + (int)this.errorCode).ToString(CultureInfo.InvariantCulture).Substring(1);
79 return "fatal error JS" + errorNum + ": " + msg;
83 public string ResourceKey(CmdLineError errorCode){
84 switch (errorCode){
85 case CmdLineError.AssemblyNotFound: return "Assembly not found";
86 case CmdLineError.CannotCreateEngine: return "Cannot create JScript engine";
87 case CmdLineError.CompilerConstant: return "Compiler constant";
88 case CmdLineError.DuplicateFileAsSourceAndAssembly: return "Duplicate file as source and assembly";
89 case CmdLineError.DuplicateResourceFile: return "Duplicate resource file";
90 case CmdLineError.DuplicateResourceName: return "Duplicate resource name";
91 case CmdLineError.DuplicateSourceFile: return "Duplicate source file";
92 case CmdLineError.ErrorSavingCompiledState: return "Error saving compiled state";
93 case CmdLineError.IncompatibleTargets: return "Incompatible targets";
94 case CmdLineError.InvalidAssembly: return "Invalid assembly";
95 case CmdLineError.InvalidCharacters: return "Invalid characters";
96 case CmdLineError.InvalidCodePage: return "Invalid code page";
97 case CmdLineError.InvalidDefinition: return "Invalid definition";
98 case CmdLineError.InvalidForCompilerOptions: return "Invalid for CompilerOptions";
99 case CmdLineError.InvalidLocaleID: return "Invalid Locale ID";
100 case CmdLineError.InvalidPlatform: return "Invalid platform";
101 case CmdLineError.InvalidTarget: return "Invalid target";
102 case CmdLineError.InvalidSourceFile: return "Invalid source file";
103 case CmdLineError.InvalidVersion: return "Invalid version";
104 case CmdLineError.InvalidWarningLevel: return "Invalid warning level";
105 case CmdLineError.MultipleOutputNames: return "Multiple output filenames";
106 case CmdLineError.MultipleTargets: return "Multiple targets";
107 case CmdLineError.MultipleWin32Resources: return "Multiple win32resources";
108 case CmdLineError.MissingDefineArgument: return "Missing define argument";
109 case CmdLineError.MissingExtension: return "Missing extension";
110 case CmdLineError.MissingLibArgument: return "Missing lib argument";
111 case CmdLineError.MissingReference: return "Missing reference";
112 case CmdLineError.ManagedResourceNotFound: return "Managed resource not found";
113 case CmdLineError.NestedResponseFiles: return "Nested response files";
114 case CmdLineError.NoCodePage: return "No code page";
115 case CmdLineError.NoFileName: return "No filename";
116 case CmdLineError.NoInputSourcesSpecified: return "No input sources specified";
117 case CmdLineError.NoLocaleID: return "No Locale ID";
118 case CmdLineError.NoWarningLevel: return "No warning level";
119 case CmdLineError.ResourceNotFound: return "Resource not found";
120 case CmdLineError.SourceFileTooBig: return "Source file too big";
121 case CmdLineError.SourceNotFound: return "Source not found";
122 case CmdLineError.UnknownOption: return "Unknown option";
124 return "No description available";